-
Notifications
You must be signed in to change notification settings - Fork 31
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
termnames #299
termnames #299
Conversation
Co-authored-by: Milan Bouchet-Valat <[email protected]>
Co-authored-by: Milan Bouchet-Valat <[email protected]>
Co-authored-by: Milan Bouchet-Valat <[email protected]>
Co-authored-by: Milan Bouchet-Valat <[email protected]>
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I get why this functionality is needed vs. coefnames (one string per "variable"), and I think StatsModels is a good home for it, but I'm not sure termnames
is quite right. some things that are terms never get named (tupleterms, matrixterms, formulaterm), some things that contain terms forward to their children while others do not (intercept term).
What about something like variablenames
? I think that better captures what folks mean when they want this, without introducing confusion about what is and is not an AbstractTerm
in the statsmodels system...
src/statsmodel.jl
Outdated
termnames(::InterceptTerm{H}) where {H} = H ? "(Intercept)" : nothing | ||
termnames(t::ContinuousTerm) = string(t.sym) | ||
termnames(t::CategoricalTerm) = string(t.sym) | ||
termnames(t::Term) = string(t.sym) | ||
termnames(t::ConstantTerm) = string(t.n) | ||
termnames(t::FunctionTerm) = string(t.exorig) | ||
# termnames(TupleTerm)) always returns a vector, even if it's just one element, e.g., | ||
# termnames((term(:a),)) | ||
termnames(ts::TupleTerm) = mapreduce(termnames, vcat, ts; init=String[]) | ||
# termnames(MatrixTerm)) always returns a vector, even if it's just one element, e.g., | ||
# termnames(MatrixTerm(term(:a))) | ||
termnames(t::MatrixTerm) = mapreduce(termnames, vcat, t.terms; init=String[]) | ||
termnames(t::InteractionTerm) = | ||
only(kron_insideout((args...) -> join(args, " & "), vectorize.(termnames.(t.terms))...)) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
these all shoudl be in terms.jl I think, with other term API functions
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
done
src/statsmodel.jl
Outdated
Return value is either a `String`, an iterable of `String`s or nothing if there | ||
no associated name (e.g. `termnames(InterceptTerm{false}())`). |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this is an interesting edge case. there is an associated name for the term, even if there's no coefficient that corresponds in the model.
@nalimilan I’m not opposed to the Thoughts on using |
@kleinschmidt GH won't let me reply to the comment so....
Yeah, I don't think that most users should call these methods directly, and |
Co-authored-by: Dave Kleinschmidt <[email protected]>
|
I'm open to other names -- it's easy enough to change |
Co-authored-by: Alex Arslan <[email protected]>
@kleinschmidt @nalimilan we could also go with the hybrid function name |
okay, it seems like @kleinschmidt is now onboard with termnames. Great! |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
looks like docs are not picking up the termnames crossref: https://github.com/JuliaStats/StatsModels.jl/actions/runs/6102408363/job/16561033364?pr=299#step:5:279
fix that and then LGTM.
Looks like you haven't noticed my last comment at #299 (comment). Not a big deal, but maybe still worth adjusting? |
xref JuliaStats/GLM.jl#428